﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;


/// <summary>
/// Summary description for CategoryDAO
/// </summary>
public class CategoryDAO1:DBConnect
{
    string SQL_SELECT = "select * from categories";
    string SQL_UPDATE_C = "update categories set [name] = @ct_name where category_id = @cid";
    
   
	public CategoryDAO1()
	{		
	}
    public IList<Category1> Get_CategoryName()
    {
        IList<Category1> list = new List<Category1>();
            try{
            SqlCommand cmd = new SqlCommand(SQL_SELECT,conn);
            if (ConnectDB())
            {

                SqlDataReader rd = cmd.ExecuteReader();
                while (rd.Read())
                {
                    Category1 ct = new Category1();
                    ct.Category_id = rd.GetInt32(0);
                    ct.Name = rd.GetString(1);
                    list.Add(ct);
                }
                Disconnect();
            }
            }catch(SqlException e)
            {
                Disconnect();
            }
        
        return list;

    }
    public int Update_by_ID(int cid,string ct_name)
    {
        
        int affectrow =0;
            try
            {
                SqlCommand cmd = new SqlCommand(SQL_UPDATE_C, conn);
                cmd.Parameters.AddWithValue("@ct_name", ct_name);
                cmd.Parameters.AddWithValue("@cid", cid);
                CategoryDAO1 ct1 = new CategoryDAO1();
                if (ConnectDB())
                {
                    affectrow = cmd.ExecuteNonQuery();
                    ct1.Update_by_ID(cid, ct_name);
                    Disconnect();
                }
             }
            catch (SqlException e1)
            {
                Disconnect();
            }                
        return affectrow;

    }
      
}